//
//  WXHomeCell.swift
//  weibo
//
//  Created by 王旭 on 16/4/20.
//  Copyright © 2016年 王旭. All rights reserved.
//

import UIKit
import SnapKit

//cell上控件公共间距
let HomeCellMargin :CGFloat = 5
//头像宽高
let IconImageWH :CGFloat = 35
//昵称字体
let NameFontSize : CGFloat = 14
//时间字体大小
let TimeFontSize : CGFloat = 10
//来源字体大小
let SourceFontSize : CGFloat = 10
//微博内容字体大小
let ContentFontSize : CGFloat = 14
//底部视图高度
let TabBarViewHeight : CGFloat = 35
//tabBar按钮字体大小
let TabBarButtonFontSize : CGFloat = 14

class WXHomeCell: UITableViewCell {
    
    //tabBar顶部约束
    var tabBarConstraint : Constraint?
    
    var statusViewModel : WXStatusViewModel?{
        didSet{
            //给originView传递数据
            originView.statusViewModel = statusViewModel
            
            
            //1.约束失效
            tabBarConstraint?.uninstall()
            //2.更新约束
            if statusViewModel?.status?.retweeted_status != nil {
                //显示状态
                reweetView.hidden = false
                //改变约束
                tabBarView.snp_updateConstraints(closure: { (make) -> Void in
                    tabBarConstraint = make.top.equalTo(reweetView.snp_bottom).constraint
                })
            //3.给reweetView数据!!!
                reweetView.statusViewModel = statusViewModel
            }else{
                //1.隐藏状态
                reweetView.hidden = true
                //2.改变约束
                tabBarView.snp_updateConstraints(closure: { (make) -> Void in
                  tabBarConstraint = make.top.equalTo(originView.snp_bottom).constraint
                })
            }
        }
        
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }


    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
//        backgroundColor = RandomColor
        //添加原创微博View
        contentView.addSubview(originView)
        contentView.addSubview(tabBarView)
        contentView.addSubview(reweetView)
        
        //做约束
        originView.snp_makeConstraints { (make) -> Void in
            make.top.leading.trailing.equalTo(contentView)
//            make.height.equalTo(150)
        }
        tabBarView.snp_makeConstraints { (make) -> Void in
           tabBarConstraint =  make.top.equalTo(reweetView.snp_bottom).constraint
            make.leading.trailing.equalTo(originView)
            make.height.equalTo(TabBarViewHeight)
        }
        reweetView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(originView.snp_bottom)
            make.leading.trailing.equalTo(originView)
//            make.height.equalTo(60)
        }
        
        contentView.snp_makeConstraints { (make) -> Void in
            make.top.leading.trailing.equalTo(self)
            make.bottom.equalTo(tabBarView)
        }
    }
    
    //懒加载
    //原创微博view
    private lazy var originView : WXOriginalStatusView = WXOriginalStatusView()
    //tabBarView
    private lazy var tabBarView : WXTabBarView = WXTabBarView()
    //转发微博view
    private lazy var reweetView : WXRetweetView = WXRetweetView()

}
